<?xml version="1.0" encoding="UTF-8"?>
<ui:composition template="/pages/mastertemplate/MasterPage.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">
	<ui:define name="content">

		<p:panel header="#{msg.tonkho_title}">

			<h:form>
				<p:commandButton style="width:150px;float: left;margin-top:10px;"
					value="#{msg.Button_export}"
					actionListener="#{TonKhoBean.downloadFileCSV}" ajax="false">
					<p:fileDownload value="#{TonKhoBean.file}" />
				</p:commandButton>
			</h:form>

			<h:form id="tonKhoForm">
				<p:growl id="growforFile" autoupdate="true"
					life="#{DataConfigBean.growlShow}" />
				<p:dataTable id="dataTable" var="ton"
					value="#{TonKhoBean.listTonKho}" paginator="true" rows="10"
					paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
					rowsPerPageTemplate="10,20,50,100"
					style="width: 100%; margin: 45px auto;">

					<f:facet name="header">
						<h:outputText value="#{msg.danhSachTonKho}"
							styleClass="tableHeader" />
					</f:facet>

					<p:column headerText="#{msg.maKhoHang}" filterBy="#{ton.khoHang}"
						filterMatchMode="contains" sortBy="#{ton.khoHang}">#{ton.khoHang}  </p:column>

					<p:column headerText="#{msg.phieuNhap}" filterBy="#{ton.phieuNhapKho}"
						filterMatchMode="contains" sortBy="#{ton.phieuNhapKho}">#{ton.phieuNhapKho}  </p:column>

					<p:column headerText="#{msg.phieuXuat}" filterBy="#{ton.phieuXuatKho}"
						filterMatchMode="contains" sortBy="#{ton.phieuXuatKho}">#{ton.phieuXuatKho}  </p:column>

					<p:column headerText="#{msg.maVatTuHangHoa}"
						filterBy="#{ton.vatTuHangHoa}" filterMatchMode="contains"
						sortBy="#{ton.vatTuHangHoa}">#{ton.vatTuHangHoa}  </p:column>


					<p:column headerText="#{msg.serialNumber}"
						filterBy="#{ton.serialNumber}" filterMatchMode="contains"
						sortBy="#{ton.serialNumber}">#{ton.serialNumber}  </p:column>

					<p:column headerText="#{msg.productName}"
						filterBy="#{ton.productName}" filterMatchMode="contains"
						sortBy="#{ton.productName}">#{ton.productName}  </p:column>

					<p:column headerText="#{msg.giaSanPham}"
						filterBy="#{ton.giaSanPham}" filterMatchMode="contains"
						sortBy="#{ton.giaSanPham}">#{ton.giaSanPham}  </p:column>

					<p:column headerText="#{msg.trangThai}">#{ton.trangThai}  </p:column>
					<p:column headerText="#{msg.lock}">#{ton.lock}  </p:column>
					<p:column headerText="#{msg.soLuong}">#{ton.soLuong}  </p:column>
					
					<p:column headerText="#{msg.table_actions}"
						style="text-align:center;min-width:10px">

						<p:commandButton styleClass="smallButton"
							icon="ui-icon ui-icon-pencil" update=":addTonKhoForm:display"
							rendered="#{UserBean.getAccessLevel() == 'WRITE'}"
							action="#{TonKhoBean.notifyEdit(ton)}"
							oncomplete="PF('TonKhoDialog').show();">

						</p:commandButton>

					</p:column>

				</p:dataTable>
				<p:dialog id="confirmRemove" header="#{msg.confirm}"
					widgetVar="confirmRemove" resizable="false">
					<table>
						<tr>
							<td><h:outputText value="#{msg.confirm_text}:" /></td>
							<td align="right"><p:commandButton value="#{msg.okButton}"
									actionListener="#{NganHangBean.removeNganHang}"
									update=":tonKhoForm" oncomplete="PF('confirmRemove').hide();" /></td>
						</tr>

					</table>
				</p:dialog>

			</h:form>


			<h:form id="addTonKhoForm">
				<p:dialog id="addTonKhodialog" header="Thêm mới/ Sửa" modal="true"
					widgetVar="TonKhoDialog" resizable="false">

					<p:panel id="display">
						<table>


							<tr>
								<td><p:outputLabel style="margin-left: 20px"
										value="#{msg.trangThai}" /></td>
								<td><p:selectOneMenu styleClass="inputText"
										value="#{TonKhoBean.tonKho.trangThai}">
										<f:selectItems value="#{TonKhoBean.listTrangThaiTonKho}"
											var="selectItem" itemLabel="#{selectItem}"
											itemValue="#{selectItem}" />
									</p:selectOneMenu></td>
							</tr>

							<tr>
								<td><p:outputLabel style="margin-left: 20px"
										value="#{msg.gia}" /></td>
								<td><p:inputText styleClass="inputText"
										value="#{TonKhoBean.tonKho.giaSanPham}">
									</p:inputText></td>

							</tr>
							<tr>

								<td></td>
								<td align="right"><p:commandButton value="Lưu"
										actionListener="#{TonKhoBean.save}"
										update=":tonKhoForm :addTonKhoForm:display"
										oncomplete="if(args.opSuccess) PF('TonKhoDialog').hide()"></p:commandButton></td>
							</tr>
						</table>
					</p:panel>
				</p:dialog>
			</h:form>

		</p:panel>

	</ui:define>
</ui:composition>
